<?php $this->regJs('echarts.min') ?>
<?php $this->regJs('candle') ?>

<style type="text/css">
    .bg {
        background: url(/images/white_bg.jpg) no-repeat center center;
        background-size: 100% 100%;
    }
    .game_header{
        padding: 12px 10px;
        border-bottom: 1px solid #eeeeee;
    }
    .user_img{
        width: 42px;
        margin-right: 6px;
        margin-top: -4px;
    }
    .ji_balance_tip{
        font-size: 13px;
        color: #878380;
    }
    .ji_balance_count{
        font-size: 12.8px;
        color: #da4931;
    }
    .ji_rehcarge_link{
        font-size: 12.8px;
        color: #da4931;
        padding: 1px 6px;
        border-radius: 3px;
        border:1px solid #da4931;
        margin-top: 7px;
        margin-left: 10px;
    }
    .other_link a{
        display: inline-block;
        font-size: 13px;
        color: #878380;
        border:1px solid #ccc;
        border-radius:3px;
        padding: 1px 6px;
        margin-top: 10px;
    }
    .game_tab{
        padding: 6px 30px;
    }
    .game_tab a{
        float: left;
        font-size: 16px;
        color: #222;
        height: 32px;
        line-height: 32px;
        padding: 0 6px;
        margin-right: 10px;
    }
    .game_tab a.active{
        border-bottom: 3px solid #da4931;
        color: #c63e2a;
    }
    .kContainer{
        height: 240px;
    }
    .game_params{
        font-size: 14.4px;
        color: #da4931;
        padding: 6px 12px;
    }
    .game_options{
        padding: 0 12px;
    }
    .game_options>.lf{
        width: 40%;
    }
    .game_options>.rt{
        width: 58%;
    }
    .game_btn{
        background: #eeeeee;
        font-size: 14.4px;
        color: #666;
        height: 32px;
        line-height: 32px;
        border-radius: 3px;
        padding: 0 10px;
    }
    .game_btn+.game_btn{
        margin-top: 10px;
    }
    .game_btn span{
        color: #da4931;
    }
    .game_btn img{
        height: 14px;
        margin-top: 10px;
    }
    .count_control_btn span{
        float: left;
        width: 50%;
        height: 32px;
        line-height: 32px;
        font-size: 24px;
        color: #666;
        border-top: 1px solid #ccc;
        text-align: center;
        background: #eeeeee;
    }
    .count_control_btn span+span{
        border-left: 1px solid #ccc;
    }
    .buy_btns a{
        width: 49%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        font-size: 16px;
        background: #da4931;
        border-radius: 4px;
        color: #fff;
    }
    .buy_btns a img{
        height: 16px;
        margin-right: 4px;
    }
    .buy_btns a+a{
        background: #2cab41;
    }
    .red{
        color: red!important;
    }
    .green{
        color: green!important;
    }
    .now_price{
        font-size: 24px;
        color: red;
        text-align: center;
        height: 42px;
        line-height: 42px;
    }
    .top_footer{
        height: 23px;
        line-height: 23px;
        font-size: 12.8px;
        color: red;
    }
    .game_mask{
        position: fixed;
        width: 100%;
        height: 100vh;
        background: rgba(0,0,0,.4);
        padding: 100px 24px 0 24px;
        display: none;
        left: 0;
        top: 0;
        z-index: 999999;
    }
    .game_mask_con{
        background: #fff;
        border-radius: 8px;
        overflow: hidden;
    }
    .game_mask_title{
        height: 48px;
        line-height: 48px;
        text-align: center;
        font-size: 14.4px;
        background: #eee;
        color: #333;
    }
    .game_order_params{
        padding: 10px 12px;
    }
    .game_order_params p{
        float: left;
        width: 50%;
        font-size: 12.8px;
        color: #333;
        height: 32px;
        line-height: 32px;
    }
    .order_btns{
        padding: 16px 24px;
    }
    .order_btns a{
        height: 40px;
        line-height: 40px;
        background: #eeeeee;
        width: 40%;
        text-align: center;
        font-size: 12.8px;
        border-radius: 6px;
    }
    .order_btns a+a{
        background: #cc3333;
        color: #fff;
    }
    .options_mask{
        position: fixed;
        width: 100%;
        height: 100vh;
        left: 0;
        top: 0;
        background: rgba(0,0,0,.5);
        z-index: 9999;
        display: none;
    }
    .options_con{
        width: 80%;
        position: absolute;
        margin-top: -25%;
        left: 10%;
        top: 50%;
        z-index: 999;
        background: white;
        border-radius: 0.2rem;
        padding: 0 20px;
    }
    .options_title{
        font-size: 12.8px;
        color: #666;
        height: 52px;
        line-height: 52px;
    }
    .options_lists span{
        float: left;
        width: calc((100% - 30px) / 3);
        height: 34px;
        line-height: 34px;
        text-align: center;
        border:1px solid #333;
        border-radius: 4px;
        margin-left: 15px;
        margin-bottom: 20px;
        font-size: 12.8px;
        color: #666;
    }
    .options_lists span:nth-child(3n + 1){
        margin-left: 0;
    }
    .custom_input{
        width: 100%;
        height: 40px;
        line-height: 40px;
        border:1px solid #ddd;
        border-radius: 4px;
        margin-bottom: 12px;
        padding: 0 10px;
    }
</style>

<!-- 选择周期 -->
<div class="circle_options options_mask">
    <div class="options_con">
        <p class="options_title">请选择交易周期 1M=1分钟</p>
        <div class="clear_fl options_lists circle_o_list">
            <?php $i = 1;foreach ($productPrice as $key => $arr): ?>
            <span  data-id="<?= $arr['id'] ?>" data-sen="<?= $arr['point'] ?>" data-shouyi="<?= $arr['one_profit'] ?>"><?= $arr['point'] ?><?= $arr['unit'] ?></span>
            <?php endforeach ?>
        </div>
    </div>
</div>

<!-- 选择投资积分 -->
<div class="disposit_options options_mask">
    <div class="options_con">
        <p class="options_title">请选择投资积分</p>
        <div class="clear_fl options_lists disposit_o_list">
            <!-- <span data-value="500">500</span>
            <span data-value="800">800</span>
            <span data-value="1000">1000</span>
            <span data-value="1500">1500</span>
            <span data-value="2000">2000</span>
            <span data-value="2500">2500</span>
            <span data-value="3500">3500</span>
            <span data-value="4000">4000</span>
            <span data-value="4500">4500</span>
            <span data-value="5000">5000</span> -->
            <input class="custom_input"  placeholder="输入投资积分" />
        </div>
    </div>
</div>





<div class="game_mask">
    <div class="game_mask_con">
        <p class="game_mask_title">确认订单</p>
        <div class="game_order_params clear_fl">
            <p>周期: <span>30s</span></p>
            <p>投资积分: <span>100</span></p>
            <p>交易品种: <span>BTB玉</span></p>
<!--            <p>服务费率: <span>3%</span></p>-->
<!--            <p>服务积分: <span>3</span></p>-->
            <p>收益比率: <span>85%</span></p>
            <p>委托方向: <span>涨</span></p>
            <p>最新价格: <span>23588.22</span></p>
        </div>
        <p class="clear_fl order_btns">
            <a href="" class="lf cancel_btn">取消</a>
            <a href="" class="rt game_confirm_btn">确定</a>
        </p>
    </div>
</div>

<div class="game_header clear_fl">
    <a class="lf" href="<?= url(['user/index']) ?>">
        <img src="/images/userImg.png" class="lf user_img">
    </a>
    <div class="lf">
        <p class="ji_balance_tip">能源分余额</p>
        <p class="ji_balance_count"><?= u()->account - u()->blocked_account ?></p>
    </div>
    <!--<a href="<?/*= url(['user/recharge']) */?>" class="lf ji_rehcarge_link">获取能源分</a>-->
    <p class="rt other_link">
        <!--<a href="<?/*= url(['user/with-draw']) */?>">兑换</a>-->
        <a href="<?= url(['site/ticket']) ?>">券</a>
        <a href="<?= url(['site/guide']) ?>">帮助</a>
    </p>
</div>

<p class="game_tab clear_fl" id="productList">
    <?php $bool=true;foreach ($productArr as $key => $arr):
        $class=($key==$pid)?'active':'';?>
    <a class="<?= $class ?>" data-id="<?= $key ?>" data-name="<?= $arr['table_name'] ?>"  data-price="<?= $arr['price'] ?>" href="<?= url(['site/index', 'pid' => $key]) ?>"><?= $arr['name'] ?>
        <span style="display: none" class="down-color p_price" id="<?= $arr['table_name'] ?>" data-istrade="1" data-point="1"><?= $arr['price'] ?></span>
        <i style="display: none;" class="down-color">↓</i>
    </a>
    <?php endforeach ?>
</p>

<p class="game_tab clear_fl" id="chart-tab">
    <a data-unit="-1" href="" >分时图</a>
    <a data-unit="0.5" href="">30S</a>
    <a data-unit="1" class="active" href="">1M</a>
    <a data-unit="3" href="">3M</a>
</p>


<div class="kContainer" id="chartContainer">

</div>

<div class="clear_fl game_params">
    <span class="lf" style="margin-right: 10px;">收益率 <span class="profit_rate">85.00</span>%</span>
    <span class="lf">预期收益： <span class="profit_count">85</span>积分</span>
    <a href="<?= url(['site/gamePosition']) ?>" class="rt">查看持仓</a>
</div>

<div class="game_options clear_fl">
    <div class="lf">
        <p class="game_btn clear_fl circle_btn">交易周期 <span>30S</span> <img class="rt" src="/images/jiantou.png"></p>
        <p class="game_btn clear_fl disposit_btn">投资能源分 <span>100</span> <img class="rt" src="/images/jiantou.png"></p>
        <p class="count_control_btn clear_fl">
            <span class="minus_btn">-</span>
            <span class="pulus_btn">+</span>
        </p>
    </div>
    <div class="rt">
        <h1 class="now_price"><?= floatval($newData['price']) ?></h1>
        <p class="clear_fl top_footer">
            <span class="lf">高  <?= floatval($newData['high']) ?></span>
            <span class="rt">低  <?= floatval($newData['low']) ?></span>
        </p>
        <p class="buy_btns clear_fl">
            <a class="lf" data-type="1" href=""><img src="/images/zhang2200.png">看涨</a>
            <a class="rt" data-type="2" href=""><img src="/images/die200.png">看跌</a>
        </p>
    </div>
</div>
<input type="hidden" id="productDirection" value="1">
<div id="kOption" style="display: none;">{}</div>
<div id="lineOption" style="display: none;">{}</div>
<!-- <div type="hidden" id="productHand" style="display: none;"></div> -->
<div id="istrade" style="display: none;">1</div>

<script type="text/javascript">
    $(".cancel_btn").click(function(e){
        e.preventDefault();
        $(this).parents(".game_mask").hide();
    });

    $(".buy_btns a").click(function(e){
        e.preventDefault();
        var circle = $(".circle_btn span").html();
        var disposit = $(".disposit_btn span").html();
        var productName = $("#productList a.active").html();
        var serverCount = disposit * 3 / 100;
        var profitRate = $(".profit_rate").html();
        var type = $(this).data("type");
        var riseFall = "涨";
        if(type == 1){
            riseFall = "涨";
        }else{
            riseFall = "跌";
        }
        var nowPrice = $(".now_price").html();
        var html = '<p>周期: <span>' + circle + '</span></p>\
            <p>投资积分: <span>' + disposit + '</span></p>\
            <p>交易品种: <span>' + productName + '</span></p>\
            <p>收益比率: <span>' + profitRate + '%</span></p>\
            <p>委托方向: <span>' + riseFall + '</span></p>\
            <p>最新价格: <span>'+ nowPrice +'</span></p>';

            $(".game_order_params").html( html );
//    <p>服务积分: <span>' + serverCount + '</span></p>\
//    <p>服务费率: <span>3%</span></p>

            $(".game_confirm_btn").attr("data-riseFall", type);
        $(".game_mask").show();
    });

    // 下单
    $(".game_confirm_btn").click(function(e){
        e.preventDefault();
        var obj = {};
        obj.rise_fall = $(this).attr("data-riseFall");
        obj.product_id = $("#productList a.active").data("id");
        obj.deposit = $(".disposit_btn span").html();
        obj.priceId = $(".profit_rate").attr("data-id");


        $.post("<?= url('order/ajaxSaveOrder')?>", {data: obj}, function (msg) { ///////更新订单  重新写接口
            if (msg.state) {
                // 下单成功
                window.location.href = "<?= url(['site/gamePosition', 'order_state' => 1]) ?>";
            }else{
                $.alert(msg.info);
            }
        });
    });

    $(".options_mask").click(function(){
        $(this).hide();
    });

    $(".options_con").click(function(e){
        e.stopPropagation();
    });

    $(".circle_btn").click(function(){
        $(".circle_options").show();
    });

    $(".circle_o_list").on("click", "span", function(){
        var html = $(this).html();
        $(".circle_btn span").html( html );

        var _id = $(this).data("id");
        var _rate = $(this).data("shouyi");
        $(".profit_rate").html( _rate ).attr("data-id", _id);

        calc();
        $(".circle_options").hide();
    });

    $(".disposit_btn").click(function(){
        $(".disposit_options").show();
    });

    $(".disposit_o_list").on("click", "span", function(){
        var html = $(this).html();
        $(".disposit_btn span").html( html );
        $(".disposit_options").hide();

        calc();
    });

    $(".custom_input").blur(function(){
        var html = $(this).val();
        $(this).val("");
        if( isNaN(html) ){
            $.alert("请输入数字");
            return false;
        }
        if( parseFloat(html) <= 500 ){
            $.alert("投资积分数不小500");
            return false;
        }
        $(".disposit_btn span").html( html );
        $(".disposit_options").hide();
        calc();
    });

    function calc(){
        var rate = parseFloat( $(".profit_rate").html() );
        var disposit = parseFloat( $(".disposit_btn span").html() );
        var disposit_count = disposit * rate / 100;
        $(".profit_count").html( disposit_count );
    }

    $(".count_control_btn").on("click", "span", function(){
        var disposit = parseFloat( $(".disposit_btn span").html() );
        if( $(this).hasClass("minus_btn") ){ // 减
            if( disposit <= 100 ){
                return false
            }
            disposit -= 100;
        }else{ // 加
            disposit += 100;
        }
        $(".disposit_btn span").html( disposit );
        calc();
    });


    $(function(){
        $(".circle_o_list span:first-child").trigger("click");
    });

    
</script>











